package com.softmaker.service;

import com.softmaker.entity.UserInfo;
import com.softmaker.entity.Video;
import com.softmaker.repository.VideoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideoService {
    @Autowired
    private VideoRepository repository;
    public Video addVideo(Video video){
        return repository.save(video);
    }
    public Video findVideo(String videoName){
        return repository.findVideoByVideoName(videoName);
    }
    public List<Video> listVideo(){
        return repository.findAll();
    }
    public Video findVideoImage(String videoImageName){
        return repository.findVideoByVideoImageName(videoImageName);
    }

    public void deleteVideo(Video video){
        repository.deleteById(video.getVideoId());
    }
    public String bytesToBinaryString(byte[] bytes) {
        StringBuilder binaryStringBuilder = new StringBuilder();
        for (byte b : bytes) {
            // 将每个字节转换为8位的二进制字符串
            String binary = String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');
            binaryStringBuilder.append(binary);
        }
        return binaryStringBuilder.toString();
    }
}
